package com.yunban.project.statistic.service.impl;

import com.yunban.project.article.service.ArticleService;
import com.yunban.project.statistic.model.vo.StatisticsResp;
import com.yunban.project.statistic.service.StatisticsService;
import com.yunban.project.template.service.TemplateCollectService;
import com.yunban.project.template.service.TemplateService;
import jakarta.annotation.Resource;
import net.lab1024.sa.base.common.util.SmartRequestUtil;
import org.springframework.stereotype.Service;

/**
 * @author: lijiajun
 * @date: 2024-11-29
 * @version: 1.0
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Resource
    private TemplateService templateService;

    @Resource
    private ArticleService articleService;

    @Resource
    private TemplateCollectService templateCollectService;

    @Override
    public StatisticsResp getMyStatistics() {
        // 获取用户id
        long userId = SmartRequestUtil.getUserId();
        StatisticsResp statisticsResp = new StatisticsResp();
        // 已保存文章数
        statisticsResp.setSaveArticleCount(this.articleService.findByUserId(userId).size());
        // 已收藏模板数
        statisticsResp.setTemplateCollectCount(this.templateCollectService.getUserCollectList(userId).size());
        return statisticsResp;
    }
}
